// 16位随机字符串
const createRandStr = function (bit = 16) {
  let chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
  /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  let maxPos = chars.length;
  var str = "";
  for (let i = 0; i < bit; i++) {
    str += chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return str;
};

// 是否IOS设备
const isIos = function () {
  let u = navigator.userAgent;
  let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  if (isiOS) {
    return true;
  } else {
    return false;
  }
};

// 是否微信内置浏览器
const isWeixin = function () {
  let ua = window.navigator.userAgent.toLowerCase();
  if (ua.match(/MicroMessenger/i) == "micromessenger") {
    console.log("weixin");
    return true;
  } else {
    console.log("qita");
    return false;
  }
};

// 验证是否Json字符串
const checkJson = function(str){
  if (typeof str == "string") {
    try {
      var obj = JSON.parse(str);
      if (typeof obj == "object" && obj) {
        return true;
      } else {
        return false;
      }
    } catch (e) {
      return false;
    }
  }
  return false;
}

const ymdHms2ymd = function(date){
  let arr = date.split(' ')
  return arr[0];
}
export default {
  createRandStr,
  isIos,
  isWeixin,
  checkJson,
  ymdHms2ymd
};
